/**
 * Ingenius-Group S.A.S
 *
 * Project: SAU
 * File: GuidelinesServiceImpl.java
 * Date: 01/03/2011
 */

package com.ingenius.sau.server.service;

import java.util.List;

import com.extjs.gxt.ui.client.data.BasePagingLoadConfig;
import com.extjs.gxt.ui.client.data.PagingLoadResult;
import com.ingenius.sau.client.service.GuidelinesService;
import com.ingenius.sau.server.persistence.DAOFactory;
import com.ingenius.sau.server.persistence.FactorDAO;
import com.ingenius.sau.server.persistence.FeatureDAO;
import com.ingenius.sau.server.persistence.GuidelineDAO;
import com.ingenius.sau.server.persistence.IndicatorDAO;
import com.ingenius.sau.server.persistence.jdo.JdoDAOFactory;
import com.ingenius.sau.shared.model.guidelines.Factor;
import com.ingenius.sau.shared.model.guidelines.Feature;
import com.ingenius.sau.shared.model.guidelines.Guideline;
import com.ingenius.sau.shared.model.guidelines.Indicator;
import com.ingenius.sau.shared.util.filter.Filter;

/**
 * Class <strong>GuidelinesServiceImpl</strong>
 * 
 * @author Jesus David
 * @version 0.1
 */
@SuppressWarnings("serial")
public class GuidelinesServiceImpl extends AbstractService implements
		GuidelinesService {

	private DAOFactory daoFactory;
	private GuidelineDAO guidelineDAO;
	private FactorDAO factorDAO;
	private FeatureDAO featureDAO;
	private IndicatorDAO indicatorDAO;

	public GuidelinesServiceImpl() {
		daoFactory = JdoDAOFactory.getInstance();
		guidelineDAO = daoFactory.createGuidelineDAO();
		factorDAO = daoFactory.createFactorDAO();
		featureDAO = daoFactory.createFeatureDAO();
		indicatorDAO = daoFactory.createIndicatorDAO();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.ingenius.sau.client.service.GuidelinesService#saveOrUpdateGuideline
	 * (com.ingenius.sau.shared.model.guidelines.Guideline)
	 */
	@Override
	public Boolean saveOrUpdateGuideline(Guideline guideline) {
		if (guideline.getId() == null) {
			return guidelineDAO.save(guideline);
		}
		return guidelineDAO.update(guideline);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.ingenius.sau.client.service.GuidelinesService#deleteGuideline(java
	 * .lang.String)
	 */
	@Override
	public Boolean deleteGuideline(String id) {
		return guidelineDAO.delete(id);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.ingenius.sau.client.service.GuidelinesService#getGuideline(java.lang
	 * .String)
	 */
	@Override
	public Guideline getGuideline(String id) {
		return guidelineDAO.get(id);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.ingenius.sau.client.service.GuidelinesService#findGuidelines(java
	 * .util.List, com.extjs.gxt.ui.client.data.BasePagingLoadConfig)
	 */
	@Override
	public PagingLoadResult<Guideline> findGuidelines(List<Filter> filters,
			BasePagingLoadConfig config) {

		return super.find(guidelineDAO, filters, config);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.ingenius.sau.client.service.GuidelinesService#saveOrUpdateFactor(
	 * com.ingenius.sau.shared.model.guidelines.Factor)
	 */
	@Override
	public Boolean saveOrUpdateFactor(Factor factor) {
		if (factor.getId() == null) {
			return factorDAO.save(factor);
		}
		return factorDAO.update(factor);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.ingenius.sau.client.service.GuidelinesService#deleteFactor(java.lang
	 * .String)
	 */
	@Override
	public Boolean deleteFactor(String id) {
		return factorDAO.delete(id);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.ingenius.sau.client.service.GuidelinesService#getFactor(java.lang
	 * .String)
	 */
	@Override
	public Factor getFactor(String id) {
		return factorDAO.get(id);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.ingenius.sau.client.service.GuidelinesService#findFactors(java.lang
	 * .String, java.util.List,
	 * com.extjs.gxt.ui.client.data.BasePagingLoadConfig)
	 */
	@Override
	public PagingLoadResult<Factor> findFactors(List<Filter> filters,
			BasePagingLoadConfig config) {

		return super.find(factorDAO, filters, config);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.ingenius.sau.client.service.GuidelinesService#saveOrUpdateFeature
	 * (com.ingenius.sau.shared.model.guidelines.Feature)
	 */
	@Override
	public Boolean saveOrUpdateFeature(Feature feature) {
		if (feature.getId() == null) {
			return featureDAO.save(feature);
		}
		return featureDAO.update(feature);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.ingenius.sau.client.service.GuidelinesService#deleteFeature(java.
	 * lang.String)
	 */
	@Override
	public Boolean deleteFeature(String id) {
		return featureDAO.delete(id);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.ingenius.sau.client.service.GuidelinesService#getFeature(java.lang
	 * .String)
	 */
	@Override
	public Feature getFeature(String id) {
		return featureDAO.get(id);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.ingenius.sau.client.service.GuidelinesService#findFeatures(java.lang
	 * .String, java.util.List,
	 * com.extjs.gxt.ui.client.data.BasePagingLoadConfig)
	 */
	@Override
	public PagingLoadResult<Feature> findFeatures(List<Filter> filters,
			BasePagingLoadConfig config) {

		return super.find(featureDAO, filters, config);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.ingenius.sau.client.service.GuidelinesService#saveOrUpdateIndicator
	 * (com.ingenius.sau.shared.model.guidelines.Indicator)
	 */
	@Override
	public Boolean saveOrUpdateIndicator(Indicator indicator) {
		if (indicator.getId() == null) {
			indicatorDAO.save(indicator);
		}
		return indicatorDAO.update(indicator);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.ingenius.sau.client.service.GuidelinesService#deleteIndicator(java
	 * .lang.String)
	 */
	@Override
	public Boolean deleteIndicator(String id) {
		return indicatorDAO.delete(id);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.ingenius.sau.client.service.GuidelinesService#getIndicator(java.lang
	 * .String)
	 */
	@Override
	public Indicator getIndicator(String id) {
		return indicatorDAO.get(id);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.ingenius.sau.client.service.GuidelinesService#findIndicators(java
	 * .lang.String, java.util.List,
	 * com.extjs.gxt.ui.client.data.BasePagingLoadConfig)
	 */
	@Override
	public PagingLoadResult<Indicator> findIndicators(List<Filter> filters,
			BasePagingLoadConfig config) {

		return super.find(indicatorDAO, filters, config);
	}

}
